﻿Imports System.Text

Public Class ReportFactory

    Public Function CreateReportText(t As Type) As String
        Dim atr As TableAttribute = TableAttributeReader.Read(t)
        Return Me.CreateReportText(atr)
    End Function

    Public Overridable Function CreateReportText(t As TableAttribute) As String
        Dim s As New StringBuilder
        s.Append(Me.CreateTableText(t))
        s.Append(Me.CreateColumnText(t))
        Return s.ToString
    End Function

    Public Overridable Function CreateTableText(t As TableAttribute) As String
        Dim s As New StringBuilder
        s.AppendFormat(String.Format("TableName:{0}, LoadTableName:{1}", t.TableFullName, t.LoadTableFullName))
        s.AppendLine()
        s.AppendFormat(String.Format("ModelType:{0}", t.ModelType.FullName))
        s.AppendLine()

        Return s.ToString
    End Function

    Public Overridable Function CreateColumnText(t As TableAttribute) As String
        Dim s As New StringBuilder
        s.AppendLine("No,PK,Column,Null,Property")

        Dim i As Integer = 1
        For Each item In t.Columns
            Dim key As String = If(item.IsPrimaryKey, "Y", String.Empty)
            Dim null As String = If(item.IsNullable, "Y", String.Empty)
            Dim prop As String = String.Format("{0}.{1}", item.PropertyInfo.DeclaringType.Name, item.PropertyInfo.Name)
            s.AppendFormat("{0},{1},{2},{3},{4}", i, key, item.ColumnName, null, prop)
            s.AppendLine()
            i += 1
        Next

        Return s.ToString
    End Function

End Class
